{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a44f9110",
   "metadata": {},
   "source": [
    "* 日期：2022-10-12 week08（周三）\n",
    "* 课程：python\n",
    "* 记录人：lishengqing"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b44fa583",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. 有序的数据结构-字符串  \n",
    ">> 1. 字符串的基本概念 \n",
    ">>>\n",
    "\n",
    ">> 2. 字符串的性质和方法  \n",
    "> 2. 有序的数据结构-列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb7e91b7",
   "metadata": {},
   "source": [
    "## 1.字符串的性质和方法  \n",
    "\n",
    "* 字符串的性质\n",
    "> 1.字符串的有序性  \n",
    "> 2.字符串是有长度的  \n",
    ">> 1.使用len（）检查字符串的长度  \n",
    "* 字符串的基础方法(运算法则)\n",
    ">1. 字符串的取值 ：str[index]  \n",
    ">2. 字符串的切片：text[start:stop](stop取不到)\n",
    ">3. 字符串的拼接用：text[x]+text[y]\n",
    ">4. in检查是否存在\n",
    "* 字符串的一般方法(function/methods 函数/方法)\n",
    ">1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1d5470c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "51b0b561",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f286f3d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ae422cdb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "987c7cec",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [14]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[100]  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2f94c0a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "de0bef12",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]+text[1]+text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "3cf224bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "435f363e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "59be95d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "2f5f6dea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院团'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a561517f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1:-3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63488a07",
   "metadata": {},
   "source": [
    "* in 检查成员对象\n",
    "* in "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "e1fa48d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "704f46b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\") 检查出现多少次"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df0c1c6c",
   "metadata": {},
   "source": [
    "* isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "d14222a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "print(19)\n",
    "print(\"19\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "8fdf8693",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "c508ad3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "1df3a9cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65985cf6",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意：字符串是对字符进行操作，列表是对items元素进行操作"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e93d6f11",
   "metadata": {},
   "source": [
    "## 2.有序的数据结构-列表  \n",
    "\n",
    "* 1.列表的概念和基本性质  \n",
    "\n",
    "* 2.列表的一般方法(如何学习)\n",
    ">1. 使用.Tab键查看列表的方法\n",
    ">2. 使用help(查看方法的使用规则)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a97fc72f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1,4,9,16,25] # 列表里面放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "fb455488",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "8abf4f9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "925c6959",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares.count(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "2134ead2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "3c274bac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9cf915af",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca4a5e4b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "1e56349b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"] # 列表里面放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "34a74d89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Marry']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "3282cca4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 18, '李华', 20]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"Jack\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "a42cc1fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Marry']"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出\"Jack\",\"Marry\"用切片的方法 步长为2\n",
    "names[:3:2]\n",
    "names[0:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ac2d177",
   "metadata": {},
   "source": [
    "   * 2.列表的一般方法(如何学习)\n",
    "    >1 增加\n",
    "    >2.删除\n",
    "    >3.改\n",
    "    >4.查：in\n",
    ">1. 使用.Tab键查看列表的方法（names.Tab\n",
    ">>2.append 增加到结尾  insert  插入 pop  增加 remove 移除\n",
    ">2. 使用help(查看方法的使用规则)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62621c76",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "813e783e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "75273f7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"] # 列表里面放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3149f093",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "bd0ea6ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "c8f73d9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "dc2d9147",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09939104",
   "metadata": {},
   "source": [
    "# 课后作业  \n",
    "* 尝试所有列表的方法\n",
    "* 总结列表的方法学习心得（表格形式总结）  \n",
    "|列表的方法|细节|使用方法|备注|  \n",
    "|----------|----|--------|----|\n",
    "|append|---|list.append(object)|注意：增加在末尾|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2413bdcb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
